define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'yiliao/promotion/index' + location.search,
                    add_url: 'yiliao/promotion/add',
                    edit_url: 'yiliao/promotion/edit',
                    del_url: 'yiliao/promotion/del',
                    multi_url: 'yiliao/promotion/multi',
                    import_url: 'yiliao/promotion/import',
                    table: 'yiliao_promotion',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        // {field: 'pro.name', title: __('Yiliao_pro_id')},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'start', title: __('Start'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'end', title: __('End'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        // {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        // {field: 'homedata', title: __('Homedata'), searchList: {"1":__('Homedata 1'),"0":__('Homedata 0')}, formatter: Table.api.formatter.normal},
                        // {field: 'paixu', title: __('Paixu')},
                        {field: 'status', title: __('Status'), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons:[
                                {
                                    name:'daihui',
                                    text:'报名信息',
                                    //icon: 'fa fa-share',
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    extend:' target="_blank" data-area=\'["90%","90%"]\'',
                                    url:function(row){
                                        return "yiliao/proenlist/index?ids="+row.id;
                                    },
                                    visible:function(row){
                                        return true;
                                        if(row.status == 'no'){
                                            return true;
                                        }
                                    }
                                },
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
